<?php
class CategoriesComponent extends Object{
	var $components = array( 'Auth','Session','RequestHandler');
	var $helpers = array('Session','Html');
	/**
	 * 
	 * Destinantions Dictionary
	 * @return array
	 */
	public function categories($controller=null,$user_id=null){
		$this->Categories =& $this->getModel('Categories');
	    if(!$this->Categories){
	      return false;
	    }
	    if($controller != 'zamowienia'){
			return $this->Categories->find('threaded', array('conditions'=>array('controller'=>$controller),'order' => array('lft')));
	    }else{
	    	$joins = array();
	    	array_push($joins, array('table' => 'users_categories', 'alias' => 'UsersCategory', 'type' => 'INNER', 'conditions' => array( 'UsersCategory.category_id = Categories.id')));
	    	return $this->Categories->find('threaded', array('conditions'=>array('Categories.controller'=>$controller,'UsersCategory.user_id'=>$user_id),'joins'=>$joins,'order' => array('Categories.lft')));
	    }
	}
	
		
	private function &getModel($name = null) {
		$model = null;
		if (!$name) {
			$name = 'Categories';
		}    
		if($name){
			if (PHP5) {
				$model = ClassRegistry::init($name);
			} else {
				$model =& ClassRegistry::init($name);
			}

			if (empty($model)) {
//				$this->_error('FileUpload::getModel() - Model is not set or could not be found');
				return null;
			}
		}
		return $model;
	}	
}